﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Net;
using System.Net.Sockets;

namespace UdpBroadcastTest
{
    class Program
    {
        static void Main(string[] args)
        {
            string input = Console.ReadLine();
            if (input == "0")
            {
                Client();
            }
            else
            {
                Server();
            }
        }

        private static void Client()
        {
            UdpClient client = new UdpClient(1122);
            byte[] bytes = Encoding.Default.GetBytes("Hello world!");

            IPEndPoint ip = new IPEndPoint(IPAddress.Broadcast, 1123);

            client.Send(bytes, bytes.Length,ip);
            Console.ReadLine();
        }

        private static void Server()
        {
            UdpClient server = new UdpClient(1123);
            
            IPEndPoint ip = new IPEndPoint(IPAddress.Any, 0);
            byte[] bytes = server.Receive(ref ip);

            string str = Encoding.Default.GetString(bytes);
            Console.WriteLine(str);
            Console.ReadLine();
            
        }
    }
}
